<template>
  <div>
    <p style="text-align: center">侧壁温度折线图</p>
    <div id="line" style="height: 400px;width: 600px;"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  data() {
    return {
      chart: null,
      Data: [
        {high: 50, value: 100},
        {high: 100, value: 200},
        {high: 150, value: 150},
        {high: 200, value: 300},
        {high: 250, value: 250},
        {high: 300, value: 180},
      ],
      options: {

      },
      toolbox: {}
    }
  },
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      this.chart = echarts.init(document.getElementById('line'));
      function getExplanationForSeries(seriesName, value) {
        return undefined;
      }

      this.options = {
        legend: {
          data: ['0°侧壁温度线','45°侧壁温度线','90°侧壁温度线','135°侧壁温度线']
        },
        tooltip: {
          trigger: 'axis', // 触发方式为坐标轴触发
          axisPointer: {
            type: 'cross', // 类型为十字准星
            crossStyle: {
              color: '#ccc', // 十字准星颜色
              width: 2, // 十字准星线宽
              type: 'dashed', // 十字准星线类型为虚线
            },
          },
          backgroundColor: 'rgba(255, 255, 255, 0.8)', // 提示框背景颜色
          borderColor: '#333', // 提示框边框颜色
          borderWidth: 1, // 提示框边框宽度
          padding: 10, // 提示框内边距
          textStyle: {
            color: '#333', // 提示框文本颜色
          },
          formatter: function(params) {
            // 格式化显示多个曲线的数据
            let tooltipContent = `高度: ${params[0].name}m<br/>`;
            for (let i = 0; i < params.length; i++) {
              const seriesName = params[i].seriesName;
              const value = params[i].value;
              tooltipContent += `${seriesName}:${params[i].data}°C<br/>`;
            }
            return tooltipContent;

          },
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
          show: true,
          xAxis: {
            axisLine: {
              lineStyle: {
                type: 'dashed', // 虚线样式
                color: '#ccc', // 自定义颜色
              },
            },
            splitLine: { // 横向辅助虚线（网格线）
              lineStyle: {
                type: 'dashed',
                color: '#ccc',
              },
              show: true,
            },
          },
          yAxis: {
            axisTick: {
              lineStyle: {
                type: 'dashed',
                color: '#ccc',
              },
            },
            splitLine: { // 纵向辅助虚线（网格线）
              lineStyle: {
                type: 'dashed',
                color: '#ccc',
              },
              show: true,
            },
          },
        },
        xAxis: {
          type: 'value',
          axisLabel: {
            formatter: '{value} °C'
          }
        },
        yAxis: {
          type: 'category',
          axisLine: { onZero: false },
          axisLabel: {
            formatter: '{value} m'
          },
          boundaryGap: true,
          data: ['17.79', '20.28', '22.78', '24.65', '26.83', '28.71', '30.89', '33.39', '35.49']
        },
        graphic: [
          {
            type: 'group',
            rotation: Math.PI / 4,
            bounding: 'raw',
            right: 110,
            bottom: 110,
            z: 100,
          },
          {
            type: 'group',
            left: '10%',
            top: 'center',
          }
        ],
        series: [
          {
            name: '0°侧壁温度线',
            type: 'line',
            smooth: true,
            data: [41, 64, 59, 80, 84, 116, 166, 122, 136],

          },
          {
            name: '45°侧壁温度线',
            type: 'line',
            smooth: true,
            data: [35,55,75,89,88,90,123,223,250]
          },
          {
            name: '90°侧壁温度线',
            type: 'line',
            smooth: true,
            data: [22,89,54,99,100,135,150,220,230]
          },
          {
            name: '135°侧壁温度线',
            type: 'line',
            smooth: true,
            data: [33,34,55,66,77,88,99,110,180]
          }
        ]
      };
      this.chart.setOption(this.options);
      window.addEventListener('resize', this.onResize);
    },
    onResize() {
      if (this.chart) {
        this.chart.resize();
      }
    },
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.onResize);
    if (this.chart) {
      this.chart.dispose();
    }
  }


}
</script>

<style scoped>

</style>
